package ext.tianma.part;

import java.io.UnsupportedEncodingException;
import java.rmi.RemoteException;

import org.apache.log4j.Logger;

import ext.com.iba.IBAUtil;
import ext.generic.util.Generic;
import wt.fc.WTObject;
import wt.part.WTPart;
import wt.util.WTException;

/**
 * 半成品编码与镀膜类型的校验,在半成品申请编码流程中调用校验。
 * @author xuge_ning
 *
 */
public class SemfinishGoodUtil {
	
	
	/*进阶使用，进阶读取文件RawMaterialsAndClassCode。xls,seq sheet页
	public final static String c1 = "0123456789";
	public final static String c2 = "ABCDEFGH";
	public final static String c3 = "JKLMNPQR";
	*/
	//properties文件位置
	private static String filePath = "/ext/tianma/cfg/TianmaPro.properties";
	public static Logger logger = Logger.getLogger(SemfinishGoodUtil.class.getName());
	
	/*
	 * 镀膜类型-----------------半成品编码末位
	 *CF侧镀ITO，TFT侧不镀膜  ------0
	 * CF侧镀ATO，TFT侧不镀膜------A
	 * CF侧镀ATO，TFT侧镀ITO-----J
	 * CF侧不镀膜，TFT侧镀ITO；-----S
	 */
	public static boolean checkNum(String number,WTObject wto){
		
		
		boolean flag = true;
		if(wto != null && number != null && !("".equals(number))){
			
			System.out.println("<<<<<进入半成品编码校验方法");
			System.out.println("WTObject的类型,getConceptualClassname:" + wto.getConceptualClassname());
			//System.out.println("WTObject,getDisplayType()" + wto.getDisplayType());
			
			if(wto instanceof WTPart){
				WTPart part = (WTPart)wto;
				try {
					String coatingType = (String) IBAUtil.getIBAValue(part, "Coatingtype");
					
					System.out.println("coatingType的值：" + coatingType);
					
					if(coatingType != null && !("".equals(coatingType))){
						
						number = number.trim();
						System.out.println("半成品编码：" + number);
						String c = String.valueOf(number.charAt(number.length()-1));
						System.out.println("半成品编码最末位：" + c);
						Object value = Generic.getStrFromProperties(coatingType, filePath);
						if(value != null && !c.equals(value.toString())){
							flag = false;
						}
					}
				} catch (WTException e) {
					e.printStackTrace();
				} catch (RemoteException e) {
					e.printStackTrace();
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
			}
		}
		System.out.println("flag=" + flag);
		return flag;
	}
	
}
